package com.iocup.keybastion.authorize.element;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xyjxust
 * @create 2022/3/2 11:49
 **/
public class DefaultAuthElementService implements AuthElementService {

    private List<AuthElementProvider> elementProviders = new ArrayList<>();

    public List<AuthElement> findElement(String key) {
        List<AuthElement> authElements = new ArrayList<>();
        elementProviders.forEach(metaSourceProvider -> authElements.addAll(metaSourceProvider.getAuthElement(key)));
        return authElements;
    }

    @Override
    public AuthElementService addProvider(AuthElementProvider provider) {
        elementProviders.add(provider);
        return this;
    }

    @Override
    public List<AuthElement> getAuthElement(String key) {
        return findElement(key);
    }
}
